<!--
 @description 经销商联系人信息
 @fileName Contacts.vue
 @author zengqiongying
 @created 2023/04/28 13:54:59
-->
<template>
  <div>
    <Card v-for="(item, i) in list" :key="`${i}-${item.code}`">
      <template #title>
        <div class="card-header">
          <span class="name"><span class="icon"></span>{{ item.name }}</span>
        </div>
      </template>
      <Cell
        v-if="['A', 'B', 'C'].includes(item.changeType)"
        title="变更类型"
        :modelValue="item.changeType === 'B' ? '新增' : item.changeType === 'A' ? '变更' : '停用'"
        readonly
      />
      <ContactsItem :modelValue="item" hide-name />
    </Card>
    <qmp-empty v-if="list.length === 0" description="暂无经销商联系人" image-size="60px" />
  </div>
</template>

<script lang="ts">
  import { reactive, toRefs } from 'vue'
  import { useRoute } from 'vue-router'
  import Card from '@/components/Card/index.vue'
  import Cell from '@/components/Cell/index.vue'
  import ContactsItem from '../../components/Contacts/ItemView.vue'
  import { detail } from '@/apis/dealerMarketing/ArchiveChange'
  import { ContactsMixin } from '../../mixins/Contacts'
  const none: any[] = [null, undefined, '']
  interface datasModle {
    [key: string]: any
  }
  export default {
    name: 'DealerArchiveChangeDetailContacts',
    components: { Card, Cell, ContactsItem },
    setup() {
      const $route = useRoute()

      /* const datas = reactive<datasModle>({
        id: $route.query.id || '',
        list: []
      })
      const getDetailList = () => {
        const id = `${datas.id}`
        detail(id).then((res: any) => {
          const contacts = res.data?.contactDTOS || []
          const list: any[] = []
          const dtos = contacts.filter((v: any) => v.contactScope === 1)
          dtos.forEach((e: any) => {
            if (none.includes(e.contactId)) {
              list.push(e)
            } else {
              // 去重，若isbefore=1和isbefore=0 都存在，取isbefore=0的数据
              const i = list.findIndex((v) => v.contactId === e.contactId)
              if (i > -1) {
                const o = list[i]
                if (o.isBefore === 1 && e.isBefore !== 1) {
                  list[i] = e
                }
              } else {
                list.push(e)
              }
            }
          })
          datas.list = list
        })
      } */

      const { datas, getList } = ContactsMixin(1)
      datas.id = $route.query.id || ''
      getList()

      return {
        ...toRefs(datas)
      }
    }
  }
</script>
<style lang="less" scoped>
  @import url('../../styles/common.less');
</style>
